function betBill(){
    $.ajax({
        url: "http://127.0.0.1:9000/selectBet",
        type: "POST",
        contentType:"application/x-www-form-urlencoded;charset=UTF-8",
        headers: "Access-Control-Allow-Headers",
        dataType: "json",
        timeout: 5000,
        xhrFields:{
            withCredentials: true
        },
        success:function (result){
            showDate(result.data.bet)
            console.log(result);
        },
        error:function (){
            alert("请求失败")
        }
    })
}
function showDate(data) {
    var table = $('#betBill');
    table.empty();
    table.append('<tr><td>id</td><td>开奖期数</td><td>定位</td><td>类型</td><td>金额</td><td>时间</td></tr>');
    for (var i=0;i<data.length;i++) {
        var str = '<tr><td>'+data[i].id+'</td><td>'+data[i].numbers+'</td><td>'+data[i].site+'</td><td>'+data[i].type+'</td><td>'+data[i].bet+'</td><td>'+data[i].currentDate+'</td></tr>';
        table.append(str);
    }
}
var aa;
(function historyLucky(){
    $.ajax({
        url: "http://127.0.0.1:9000/selectHistory",
        type: "POST",
        contentType:"application/x-www-form-urlencoded;charset=UTF-8",
        headers: "Access-Control-Allow-Headers",
        dataType: "json",
        timeout: 5000,
        xhrFields:{
            withCredentials: true
        },
        success:function (result){
            aa = result.data.list;
            showDate1(aa)
            showMessage()
            console.log(result);
        },
        error:function (){
            alert("请求失败")
        }
    })
})()
function showMessage(){
    var showMessage = {
        numbers: aa[0].numbers
    }
    $.ajax({
        url: "http://127.0.0.1:9000/queryLucky",
        type: "POST",
        contentType:"application/x-www-form-urlencoded;charset=UTF-8",
        headers: "Access-Control-Allow-Headers",
        data: showMessage,
        dataType: "json",
        timeout: 5000,
        xhrFields:{
            withCredentials: true
        },
        success:function (result){
            // alert(result.message)
            console.log(result.message)
            showMessage1(result)
        },
        error:function (){
            alert("请求失败");
        }
    })
}
function showMessage1(data){
    var lucky = $('#message');
    lucky.append(data.message);
}
function showDate1(data) {
    var lucky = $('#lucky');
    lucky.append(data[0].lucky);

    var table = $('#historyLucky');
    table.empty();
    table.append('<tr><td>id</td><td>开奖期数</td><td>开奖数字</td><td>时间</td></tr>');
    for (var i=0;i<16;i++) {
        var str = '<tr><td>'+(i+1)+'</td><td>'+data[i].numbers+'</td><td>'+data[i].lucky+'</td><td>'+data[i].currentDate+'</td></tr>';
        table.append(str);
    }

}
(function selectUserInfo(){
    $.ajax({
        url: "http://127.0.0.1:9000/selectUserInfo",
        type: "POST",
        contentType:"application/x-www-form-urlencoded;charset=UTF-8",
        headers: "Access-Control-Allow-Headers",
        dataType: "json",
        timeout: 5000,
        xhrFields:{
            withCredentials: true
        },
        success:function (result){
            showData2(result.data.data)
            console.log(result);
        },
        error:function (){
            alert("请求失败")
        }
    })
})()
function showData2(data) {
    document.getElementById('userName').value=data.username;
    document.getElementById('balance').value=data.balance;
}
function insertBet(){
    var demo=$("form>input[name='demo']:checked").val();
    var money = document.getElementById("money").value;
    var site = demo.slice(0,-2);
    var type = demo.slice(-1);
    var bet = money;
    var obj = {
        numbers: aa[0].numbers+1,
        site: site,
        type: type,
        bet: bet,
    }
    $.ajax({
        url: "http://127.0.0.1:9000/saveBet",
        type: "POST",
        contentType:"application/x-www-form-urlencoded;charset=UTF-8",
        headers: "Access-Control-Allow-Headers",
        // data: JSON.stringify(obj1),
        data: obj,
        dataType: "json",
        timeout: 5000,
        xhrFields:{
            withCredentials: true
        },
        success:function (result){
            // alert(result.message)
            document.getElementById("money").value = "";
            alert(result.message)
        },
        error:function (){
            alert("请求失败");
        }
    })
    console.log(site)
    console.log(type)
    console.log(bet)
}

